<template>
	<div class="container">
		<custom-ui bgColor="bg-gradual-orange" :isBack="true">
			<block slot="content">排行榜</block>
		</custom-ui>
		
		<view class="musicList">
			<view style="margin: 10px 0;border-bottom: 1upx solid rgba(0,0,0,0.1);">
				<view class="top-item relative" v-for="item in topRankList">
					<!-- 左边的图片 -->
					<view class="leftImage">
						<image :src="item.coverImgUrl" style="width: 100%;height: 100%;border-radius: 6px;"></image>
						<view class="collectCount" v-if="item.playCount > 0">
							<text>{{ filterPlayCount(item.playCount) }}</text>
						</view>
					</view>
					<!-- 右边的歌曲 -->
					<view class="rightMusic">
						<p class="title">{{ item.name }}</p>
						<p v-for="(val, index) in item.tracks" :key="index" class="music-item">
							<span class="index">{{ index + 1 }}.</span>
							<text class="musicName">{{ val.first }}</text>
							<text class="text">- {{ val.second }}</text>
						</p>
					</view>
				</view>
			</view>

			<view class="flex flex-wrap" style="margin-top: 10px;">
				<view class="list-item" v-for="item in rankList">
					<!-- 播放量 -->
					<view class="collectCount" v-if="item.playCount > 0">
						<text>{{ filterPlayCount(item.playCount) }}</text>
					</view>
					<!-- 图片 -->
					<image class="list-item-image" :src="item.coverImgUrl"></image>
					<view class="list-item-text">{{ item.name }}</view>
				</view>
			</view>
		</view>
		<!-- <music-control /> -->
	</div>
</template>

<script>
export default {
	data() {
		return {
			rankList: [],
			topRankList: [],
			api:['http://music.eleuu.com/toplist/detail','https://autumnfish.cn/toplist/detail']
		};
	},
	onLoad() {
		this.getRankList();
	},
	methods: {
		getRankList() {
			uni.showLoading({
				title: '加载中...'
			});
			uni.request({
				url:this.api[0],
				success:(res) =>{
					this.topRankList = res.data.list.slice(0, 4);
					this.rankList = res.data.list.slice(4);
					uni.hideLoading();
				},
				fail:(error) =>{
					uni.hideLoading();
					uni.showToast({
						 title: '连接超时',
						duration: 2000
					});
				}
			})
		},
		filterPlayCount(val) {
			if (!val || val <= 0) return 0
			else if (val < 1000) return val
			else if (val >= 1000 && val < 10000) return Math.ceil(val / 1000) + '千'
			else if (val >= 10000 && val < 100000000) return Math.ceil(val / 10000) + '万'
			return Math.ceil(val / 100000000) + '亿'
		}
	}
};
</script>

<style lang="scss" scoped>
	.container {
		width: 100%;
		height: 100%;
		.musicList {
			padding: 0 5px 0 15px;
			width: 100%;
			position: relative;
			margin-top: 20rpx;
			box-sizing: border-box;
			.top-item {
				margin-bottom: 8rpx;
				.leftImage {
					display: inline-block;
					height: 210rpx;
					width: 210rpx;
					position: relative;
				}
				.rightMusic {
					width: calc(100% - 260rpx;);
					margin-left: 40rpx;
					display: inline-block;
					.title {
						font-weight: 600;
						font-size: 32rpx;
						margin: 8px 0;
					}
					.music-item {
						width: 100%;
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
						margin-bottom: 12rpx;
						.index {
							margin-right: 3px;
						}
						.musicName {
							font-size: 28rpx;
							color: rgba(0, 0, 0, 0.7);
							margin-right: 5px;
						}
						.text {
							font-size: 12px;
						}
					}
				}
			}
			.collectCount {
				position: absolute;
				right: 5px;
				top: 3px;
				padding: 2px 8px;
				border-radius: 15px;
				color: #fff;
				z-index: 10;
				font-size: 12px;
				background: rgba(0, 0, 0, 0.15);
			}
			.list-item {
				width: calc(100% / 3 - 10px);
				margin: 8px 10px 7px 0;
				// display: inline-block;
				overflow: hidden;
				position: relative;
				border-radius: 7px;
				.list-item-image {
					height: 210rpx;
					width: 210rpx;
					border-radius: 7px;
				}
				.list-item-text {
					width: 100%;
					padding-top: 2px;
					color: #666;
					font-size: 14px;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
				}
			}
		}
	}
	
	.searchbar{
	border: #333333 solid 1px;
	border-radius:2em ;
	width:260px;
	height: 37px;
	box-shadow: 0px,0px,5px #C0C0C0;
	margin: 0 auto;
	margin-top: 10px;
	margin-bottom: 10px;
}
	.flex {
		display: flex;//弹性布局，使元素水平排列

		&-column {
			flex-direction: column;//使class是item的内部元素按列(垂直)布局
		}

		&-wrap {
			flex-wrap: wrap;//让弹性盒元素在必要的时候拆行：
		}
	}

	.justify {
		&-center {
			justify-content: center;
		}

		&-between {
			justify-content: space-between;
		}

		&-around {
			justify-content: space-around;//使元素占满一行且间距相等
		}
	}

	.align-center {
		align-items: center;//垂直方向居中布局
	}
</style>
